
#ifndef HAL_PIN_H
#define HAL_PIN_H

#include "hal_types.h"
#include "siul_lld.h"

typedef enum
{
	PIN_LOW = 0,
	PIN_HIGH = 1,
	PIN_FAILED = 2
}pin_level_en;

typedef enum
{
	PIN_MODE_IN_FLOAT  = 0,
	PIN_MODE_IN_UP     = 1,
	PIN_MODE_IN_DOWN   = 2,
	PIN_MODE_IN_ANALOG = 3,

	PIN_MODE_OUT_PUSH_PULL  = 4,
	PIN_MODE_OUT_OPEN_DRAIN = 5,

	PIN_MODE_UART_RX = 6,
	PIN_MODE_UART_TX = 7,
	PIN_MODE_CAN_RX  = 8,
	PIN_MODE_CAN_TX  = 9,
	PIN_MODE_LIN_RX = 10,
	PIN_MODE_LIN_TX= 11,

	PIN_MODE_PWM_OUT = 12,
	PIN_MODE_PWM_IN = 13,
	PIN_MODE_ICU = 14,
	PIN_MODE_IIC = 15,
	PIN_MODE_SPI_IN  = 16,
	PIN_MODE_SPI_OUT = 17,
	PIN_MODE_SPI_CS = 18,
	PIN_MODE_INTP0_16 = 19,
	PIN_MODE_DAC = 20
}pin_mode_en;

typedef enum
{
	IRQ_MODE_EDGE = 0,
	IRQ_MODE_FAIL_EDGE = 1,
	IRQ_MODE_RISE_EDGE = 2,
	IRQ_MODE_RISE_FAIL = 3,
	IRQ_MODE_HIGH_LEVEL = 4,
	IRQ_MODE_LOW_LEVEL = 5
}pin_irq_mode_en;

typedef struct
{
	uint8_t group;
	uint8_t pin;
}pin_struct_st;

typedef enum
{
	EHBLUARTLIN0RX = 0,		//方向锁电机控制PWM通信，RX
	TempleSW = 1,			//边撑开关输入检测，高电平有效
	LED = 2,				//点亮LED指示灯
	AmbL = 3,				//氛围灯电控，高电平有效
	TailL = 4,				//尾灯电控，高电平有效
	CusLockSW = 5,			//坐垫锁开关输入检测，高电平有效
	TailBL = 6,				//尾箱锁状态输入检测，高电平有效
	TailBoxLSW = 7,			//尾箱锁开关输入检测，高电平有效
	WindUp = 8,				//电动挡风上止点输入检测，低电平有效
	WindD = 9,				//电动挡风下止点输入检测，低电平有效
	DB1 = 10,				//预留调试串口TX
	WindHall = 11,			//电动挡风霍尔值输入检测，PWM/方波
	DB2 = 12,				//预留调试串口RX
	VBAT = 13,				//控制开关电源电路，高电平有效
	CANSlient = 14,			//CAN收发器唤醒脚控制
	CAN0TX = 15,			//CAN通讯，TX
	CAN0RX = 16,			//CAN通讯，RX
	BLEUARTLIN1TX = 17,		//BLE通讯，TX
	BLEUARTLIN1RX = 18,		//BLE通讯，RX
	Unlock = 19,			//解锁反馈输入检测，低电平有效
	Lock = 20,				//闭锁反馈输入检测，低电平有效
	LConerL = 21,			//左角灯控制，高电平有效
	RConerL = 22,			//右角灯控制，高电平有效
	CourL = 23,				//迎宾灯控制，高电平有效
	AmbLShort = 24,			//氛围灯短路保护ADC输入检测
	TailLShort = 25,		//尾灯短路保护ADC输入检测
	WindRShort = 26,		//电动挡风_+_-短路保护ADC输入检测
	PosLampShort = 27,		//位置灯短路保护ADC输入检测
	LConerLShort = 28,		//左角灯短路保护ADC输入检测
	RConerLShort = 29,		//右角灯短路保护ADC输入检测
	CourLShort = 30,		//迎宾灯短路保护ADC输入检测
	HSDIS = 31,				//HSD诊断：ADC采集
	BATADC = 32,			//电源电压ADC采集
	LBeamShort = 33,		//近光继电器控制短路保护ADC输入检测
	HBeamShort = 34,		//远光继电器控制短路保护ADC输入检测
	TailBLShort = 35,		//尾箱锁电控短路保护ADC输入检测
	FuelTCapShort = 36,		//油箱盖电控短路保护ADC输入检测
	CusLockShort = 37,		//坐垫锁电控短路保护ADC输入检测
	SpeakerShort = 38,		//电喇叭驱动短路保护ADC输入检测
	EHBLShort = 39,			//方向锁电源控制短路保护ADC输入检测
	PosL = 40,				//位置灯控制，高电平有效
	HSDIN1 = 41,			//HSD通道1输入
	HSDIN0 = 42,			//HSD通道0输入
	HSDDEN = 43,			//HSD诊断使能脚输入
	SpeakerDri = 44,		//电喇叭驱动，高电平有效
	FuelTCap = 45,			//油箱盖电控，高电平有效
	CusLock = 46,			//坐垫锁电控，高电平有效
	IGNRelayShort = 47,		//电源(钥匙电)继电器控制，短路保护ADC输入检测
	PowerRelay = 48,		//电源(钥匙电)继电器控制，高电平有效
	LBeam = 49,				//近光继电器控制，高电平有效
	HBeam = 50,				//远光继电器控制，高电平有效
	EHBLPowerPWM = 51,		//方向锁电源控制，输出TTL电平
	WindFShort = 54,		//电动挡风_-_+短路保护ADC输入检测
	WindF = 53,				//电动挡风_-_+控制，高电平有效
	WindR = 54,				//电动挡风_+_-控制，高电平有效
	HSDDSEL = 55,			//HSD诊断通道选择脚输入
	TailBLPower = 56,		//尾箱锁电控，高电平有效
	CusBox = 57,			//坐垫箱状态输入检测，高电平有效
	BrakeSW = 58,			//刹车开关输入检测，高电平有效
	Power = 59,				//车辆上电输入检测(旋钮锁钥匙电)，高电平有效
	AutoLSW = 60,			//自动大灯档输入检测，高电平有效
	PosLSW = 61,			//位置灯档输入检测，高电平有效
	PassingSW = 62,			//超车灯开关输入检测，高电平有效
	EmerLSW = 63,			//应急灯开关输入检测，高电平有效
	RTurnLSW = 64,			//右转灯开关输入检测，高电平有效
	LTurnLSW = 65,			//左转灯开关输入检测，高电平有效
	LBLampSW = 66,			//近光大灯档输入检测，高电平有效
	HBLampSW = 67,			//远光大灯档输入检测，高电平有效
	EHBLUARTLIN0TX = 68,	//方向锁电机控制PWM通信，TX
	PIN_INDEX_NUM
}pin_index_en;


result_en hal_pin_mode(pin_index_en index , pin_mode_en mode);
pin_level_en hal_pin_read(pin_index_en index);
void hal_pin_write(pin_index_en index , pin_level_en level);
void hal_pin_irq(pin_index_en index , pin_irq_mode_en mode , func cal_bck);
void hal_pin_irq_enabled(pin_index_en index , enabled_en en);

#endif
